package com.example.demo.service.Impl;



import com.example.demo.bean.Counsel;
import com.example.demo.bean.CounselExample;
import com.example.demo.bean.Message;

import com.example.demo.bean.MessageExample;
import com.example.demo.dao.CounselMapper;
import com.example.demo.service.ICounselService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class CounselServiceImpl implements ICounselService {
    @Resource
   private CounselMapper counselMapper;
    @Override
    public List<Counsel> query(String question, String replay,String status) {
        CounselExample  example = new CounselExample();
        if(!StringUtils.isEmpty(question)){
            example.createCriteria().andQuestionLike("%"+question+"%");
        }
        if(!StringUtils.isEmpty(replay)){
            example.createCriteria().andReplayEqualTo(replay);
        }
        if(!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusEqualTo(status);
        }

        List<Counsel> list = counselMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Counsel counsel) {
        if(counsel.getId() == null){
            counsel.setQuestionTime(new Date().getTime());
            counselMapper.insert(counsel);
        } else {
            counselMapper.updateByPrimaryKey(counsel);
        }
    }

    @Override
    public void deleteById(long id) {
        counselMapper.deleteByPrimaryKey(id);
    }



    }

